<?php

namespace admin\controller;

use admin\model\LoginModel;

//开始 SESSION
session_start();

class LoginController extends Controller{

    private $login;

    public function __construct(){
        $this->login = new LoginModel();
    }

    /**
     * 显示登陆界面
     */
    public function getLogin($parmas = null){
        return $this->view('login');
    }
    /**
     * 判断用户名和密码是否正确
     */
    public function checkLogin($params){
        $data = $this->login->checkInfo($params);
        if($data['code']){
            $_SESSION['m_id'] = $data['info']['id'];
            $_SESSION['m_portrait'] = $data['info']['portrait'];
            $_SESSION['m_create_time'] = $data['info']['create_time'];
        }
        return $data['code'];
    }
    /**
     * 退出当前用户的登陆
     */
    public function exitLogin(){
        if($_SESSION['m_id']){
            $data = $this->login->chageState(array('state'=>0,'id'=>$_SESSION['m_id']));
            if($data){
                session_destroy();      //删除SESSION
            }
            return $data;
        }
    }
}